import { JSEncrypt } from 'jsencrypt'

// rsa密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey =
  'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALryPwurGZe4ZsFoxLCarn1ikPnuWNAt\n' +
  '9qf3w9wqcHkwXUizxO3TYGWNIqmm4A0hPtCqiXR74Hllon78Byi1Q3MCAwEAAQ=='

const privateKey =
  'MIIBVwIBADANBgkqhkiG9w0BAQEFAASCAUEwggE9AgEAAkEAuvI/C6sZl7hmwWjE\n' +
  'sJqufWKQ+e5Y0C32p/fD3CpweTBdSLPE7dNgZY0iqabgDSE+0KqJdHvgeWWifvwH\n' +
  'KLVDcwIDAQABAkEAhb/bK1X2sX3UxntWfaOtQzfJ0YadNBQubG3vSw1x+sFOKT6K\n' +
  'VX3jZDNyz7KNUcvYZWQEu9Qse2qawpO8adTggQIhAORoHu+joeferu83DcoBtTGb\n' +
  'k9FdIfxKrq0aQkCI0EMJAiEA0YfjZC8cgBJiM/RhoXFciKLfXeVVkMI43li46GbB\n' +
  'hZsCIQCfbM2rFtv7rEMOVa8aQPboGV+j0w3Vu4sQ6DM2OEilgQIhAI1n/PFOzhgs\n' +
  'z/OqOP1gaQeZi89th4qTWRfNnrTRLEeDAiEArH7MvoROx09LZJIHQTYXoLLOjXxH\n' +
  'p+LS78AwnrLx5fY='

// rsa加密
export const encrypt = (txt: string) => {
  const encryptor = new JSEncrypt()
  encryptor.setPublicKey(publicKey) // 设置公钥
  return encryptor.encrypt(txt) // 对数据进行加密
}

// rsa解密
export const decrypt = (txt: string) => {
  const encryptor = new JSEncrypt()
  encryptor.setPrivateKey(privateKey) // 设置私钥
  return encryptor.decrypt(txt) // 对数据进行解密
}
